﻿using Model;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web.Script.Serialization;

namespace Util
{
    //考生排序
    public class ExamIneeSort
    {


        public static  List<ExamInee> DecodeHashExam(String content)
        {
            var examIneeList = new List<ExamInee>();
            //examIneeList = Json.DeserializeObject<Hashtable>(content);

            //注意不可使用HashTabel 不然解密的顺序会乱
            var examListDiction = JsonConvert.DeserializeObject<Dictionary<string, object>>(content);


            foreach (KeyValuePair<string, object> kvp in examListDiction)
            {
                JavaScriptSerializer Serializer = new JavaScriptSerializer();

                var tempData = Serializer.Deserialize<List<ExamInee>>(kvp.Value.ToString());


                foreach(ExamInee tempExamInee in tempData)
                {
                    examIneeList.Add(tempExamInee);
                }

            }


     


            return examIneeList;
        }

        public static List<ExamInee> buildCompany(List<Job> jobList, List<ExamInee> examIneeList)
        {
            //考生排序
            Hashtable jobHash = new Hashtable();
            Hashtable JobMumberHash = new Hashtable();

            foreach (Job item in jobList)
            {
                jobHash.Add(item.id.ToString(), new string[] { item.name, item.company });
            }

            foreach (ExamInee item in examIneeList)
            {

                string[] arr = (string[])jobHash[item.job_id];

                item.job_name = arr[0].ToString();

                item.company = arr[1].ToString();

                item.enable = true;
            }



            return examIneeList;
            
        }
    }
}
